package com.poc;

import com.poc.domain.Task;
import com.poc.service.ProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableBinding(Sink.class)
@EnableTransactionManagement
public class ProcessServiceApp {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProcessServiceApp.class);
    @Autowired
    private ProcessService processService;

    @StreamListener(Sink.INPUT)
    public void orderDispatched(String inputMsg) {
        LOGGER.info("process-service input message : " + inputMsg);
        processService.saveTask(new Task(inputMsg));
    }

    public static void main(String[] args) {
        SpringApplication.run(ProcessServiceApp.class, args);
    }
}
